#ifndef INTERRUPTS_HPP
#define INTERRUPTS_HPP

#include "types.hpp"
#include "system.hpp"

namespace system {

    typedef void (*interrupt_handler)();

    void set_interrupt_handler(byte interrupt, interrupt_handler handler);
    interrupt_handler get_interrupt_handler(byte interrupt);

    void     set_irq_handler(byte irq, void (*handler)()); //Note: this will also enable/disable the irq. (handler == null ? disable : enable)
    void   unset_irq_handler(byte irq, void (*handler)()); //Will disable the irq handler only if the current handler function is the specified handler, in any other case, nothing happens.
    void  enable_irq_handler(byte irq);
    void disable_irq_handler(byte irq);

    inline void disable_interrupts(){ asm volatile("cli"); }
    inline void  enable_interrupts(){ asm volatile("sti"); }

    inline void interrupt(byte interrupt){ asm volatile("int %[i]"::[i]"N"(interrupt)); }

}

#endif // INTERRUPTS_HPP
